package com.happymall.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@RequestMapping("/")
	public String index() {
		return "hello spring boot";
	}

	@RequestMapping("/security")
	public String security() {
		return SecurityContextHolder.getContext().getAuthentication().getName();
	}

	@RequestMapping("/hello")
	public String hello() {
		return "不验证哦";
	}

	@PreAuthorize("hasRole('ROLE_ADMIN')")
	@RequestMapping("/auth")
	public String auth() {
		return "验证哦";
	}
	@PreAuthorize("hasPermission('a')")
	@RequestMapping("/auth2")
	public String auth2() {
		return "验证哦";
	}
}
